package com.cysyz.web.modules.base.support;


import com.cysyz.web.modules.base.businesslog.domain.SysBusinessLog;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

public abstract class ServletActionContext extends ThreadLocalContext{

    private static final long serialVersionUID = -666854718275106687L;

    public static final String REQUEST = "com.cysyz.web.dispatcher.HttpServletRequest";
    public static final String RESPONSE = "com.cysyz.web.dispatcher.HttpServletResponse";
    public static final String CURRENT_BUSINESS_LOG = "com.cysyz.springmvc.support.businessLog.domain.SysBusinessLog";

    protected ServletActionContext(Map context) {
        super(context);
    }

    public static void setRequest(HttpServletRequest request) {
        ThreadLocalContext.getContext().put(REQUEST, request);
    }

    public static HttpServletRequest getRequest() {
        return (HttpServletRequest) ThreadLocalContext.getContext().get(REQUEST);
    }

    public static void setResponse(HttpServletResponse response) {
        ThreadLocalContext.getContext().put(RESPONSE, response);
    }

    public static HttpServletResponse getResponse() {
        return (HttpServletResponse) ThreadLocalContext.getContext().get(RESPONSE);
    }

    public static void setBusinessLog(SysBusinessLog businessLog) {
        ThreadLocalContext.getContext().put(CURRENT_BUSINESS_LOG, businessLog);
    }

    public static SysBusinessLog getBusinessLog() {
        return (SysBusinessLog) ThreadLocalContext.getContext().get(CURRENT_BUSINESS_LOG);
    }

    public static ServletContext getServletContext() {
        return getRequest().getServletContext();
    }

    public static ThreadLocalContext getContext() {
        return ThreadLocalContext.getContext();
    }
}